package com.example.app.components


import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.size
import androidx.compose.material.*
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Dialog

@Composable
fun DialogSample() {
    var showFlag by remember {
        mutableStateOf(false)
    }
    Column() {
        Button(onClick = {
            showFlag = true
        }) {
            Text(text = "Show Dialog")
        }
        if (showFlag) {
            // onDismissRequest点击背景或外围部分触发
            // Dialog基础用法
//            Dialog(onDismissRequest = {
//                showFlag = false
//            }) {
//                Surface(
//                    color = Color.Yellow,
//                    modifier = Modifier.size(200.dp)
//                ) {
//                    Column() {
//                        Text(text = "Dialog Content")
//                    }
//                }
//            }

            AlertDialog(
                onDismissRequest = {
                    showFlag = false
                },
                // 确定按钮
                confirmButton = {
                    TextButton(onClick = {
                        showFlag = false
                    }) {
                        Text(text = "确定")
                    }
                },
                dismissButton = {
                    TextButton(onClick = {
                        showFlag = false
                    }) {
                        Text(text = "取消")
                    }
                }
                ,
//                buttons = {
//                    Button(onClick = { /*TODO*/ }) {
//                        Text(text = "ok")
//                    }
//                    Button(onClick = { /*TODO*/ }) {
//                        Text(text = "close")
//                    }
//                },
                text = {
                    Text(text = "内容")
                },
                title = {
                    Text(text = "帮助")
                },
                backgroundColor = Color.Red,
                contentColor = Color.Yellow,
                modifier = Modifier.size(300.dp, 200.dp)
            )
        }
    }
}


@Preview(
    showSystemUi = true
)
@Composable
fun DialogSamplePreview() {
    DialogSample()
}

